package com.geovis.emergency.spd.controller.pc;


import com.geovis.common.core.api.Result;
import com.geovis.common.core.constant.SwaggerConstants;
import com.geovis.common.core.controller.BaseController;
import com.geovis.emergency.spd.biz.pc.service.IPcDisasterEventService;
import com.geovis.emergency.spd.entity.pc.entity.PcDisasterEvent;
import com.geovis.emergency.spd.entity.pc.pojo.dto.PcDisasterEventSaveDTO;
import com.geovis.emergency.spd.entity.pc.pojo.dto.PcDisasterEventUpdateDTO;
import com.geovis.emergency.spd.entity.pc.pojo.vo.PcDisasterEventVO;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Set;

/**
 * <p>
 * 应急预案指挥模块-灾害事件管理 前端控制器
 * </p>
 *
 * @author Lonsho
 * @since 2022-06-08
 */
@RestController
@RequestMapping("/pc/disaster/event")
@RequiredArgsConstructor
@Api(value = "应急预案指挥模块-灾害事件配置", tags = "应急预案指挥模块-灾害事件配置接口")
@Slf4j
@Validated
public class PcDisasterEventController extends BaseController<IPcDisasterEventService> {

    @ApiOperationSupport(order = 1)
    @ApiOperation(value = SwaggerConstants.SAVE_VALUE, notes = SwaggerConstants.SAVE_VALUE)
    @PostMapping({"/save"})
    public Result save(@RequestBody @Validated PcDisasterEventSaveDTO saveDTO) {
        baseService.savePcDisasterEvent(saveDTO);
        return Result.ok();
    }
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = SwaggerConstants.UPDATE_VALUE, notes = SwaggerConstants.UPDATE_NOTES)
    @PostMapping({"/update"})
    public Result update(@RequestBody @Validated PcDisasterEventUpdateDTO updateDTO) {
        baseService.updatePcDisasterEvent(updateDTO);
        return Result.ok();
    }
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = SwaggerConstants.LIST_VALUE, notes = SwaggerConstants.LIST_VALUE)
    @PostMapping("/getList/{disasterId}")
    public Result<List<PcDisasterEventVO>> getList(@PathVariable("disasterId") String disasterId) {
        return Result.ok(baseService.getList(disasterId));
    }
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = SwaggerConstants.GET_BY_ID_VALUE, notes = SwaggerConstants.GET_BY_ID_NOTES)
    @PostMapping("/getDetail/{id}")
    public Result<PcDisasterEventVO> getDetail(@PathVariable("id") String id) {
        return Result.ok(baseService.getDetail(id));
    }

    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "批量删除", notes = "批量删除数据")
    @ApiImplicitParams({@ApiImplicitParam(name = "idList", value = "删除id的list", required = true, dataType = "java.util.Set", paramType = "body")})
    @PostMapping("/removeByIdList")
    public Result removeByIdList(@NotNull(message = "删除的id集合不能为空") @RequestBody Set<String> idList) {
        baseService.removeBatchByIds(idList);
        return Result.ok();
    }
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "清空所有事件", notes = "清空所有事件 ")
    @PostMapping("/cleanAll/{disasterId}")
    public Result cleanAll(@PathVariable("disasterId") String disasterId){
        baseService.cleanAll(disasterId);
        return Result.ok();
    }
    @ApiOperationSupport(order = 7)
    @ApiOperation(value = "获取所有事件", notes = "预设事件")
    @PostMapping("/listAll/{pcDrillId}")
    public Result<List<PcDisasterEvent>>  listAll(@PathVariable("pcDrillId") String pcDrillId) {
        return Result.ok( baseService.listAll(pcDrillId));
    }
}
